package cn.cmcc.online.smsapi.ui.presenter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import org.json.JSONObject;

import java.util.List;

import cn.cmcc.online.smsapi.ui.model.MetaData;
import cn.cmcc.online.smsapi.ui.model.TableData;
import cn.cmcc.online.smsapi.ui.util.DataUtil;

public class MoviePresenterImpl extends MoviePresenter {
    private Context mContext = null;

    private MetaData mMetaData = null;
    public MoviePresenterImpl(Context context) {
        mContext = context;
    }

    private void showBody() {
        vista.showBody(DataUtil.getMovieData(cardData), mMetaData);
    }

    @Override
    public void bind(JSONObject data) {
        super.bind(data);
        mMetaData = DataUtil.getMetaData(cardData);
        showBody();

        List<TableData> mainDataList = DataUtil.getMainTableList(cardData);
        if (mainDataList != null && mainDataList.size() != 0) {
            vista.showMainTable(mainDataList);
        }

        List<TableData> dataList = DataUtil.getTableList(cardData);
        String tips = DataUtil.getNote(cardData);
        if (dataList != null && dataList.size() > 0) {
            vista.showTable(dataList);

            if (((mainDataList != null && mainDataList.size() != 0)||!TextUtils.isEmpty(tips))){
               vista.showSplltLine(View.VISIBLE);
            }
        }

        if (!TextUtils.isEmpty(tips) && !tips.equals("null")) {
            vista.showNote(tips);
        }
    }
}
